#ifndef PARTICLES_H
#define PARTICLES_H

#include <ClanLib/core.h>
#include <ClanLib/display.h>
#include "viewport.h"
#include "random.h"
#include <list>

struct Particle
{
	Particle *prev, *next;
	CL_Pointf pos;
	CL_Vector2 vel;
	int life;
	CL_Colorf color, deltaColor;
};

struct Emitter
{
	Emitter();
	~Emitter();

	int id;
	int flags;
	// TRANSFORM INFO
	CL_Point pos;
	float angle, angleVar;
	float speed, speedVar;
	// Particle
	Particle *particle;
	int totalParticles;
	int particleCount;
	float emitsPerFrame, emitVar;
	int life, lifeVar;
	CL_Colorf startColor, startColorVar;
	CL_Colorf endColor, endColorVar;
	// Physics
	CL_Vector2 acceleration;	
};

class ParticleManager
{
	Particle *particlePool;
	Particle *temp;
	Random random;
	std::list<Emitter> emitter;

public:
	ParticleManager();
	~ParticleManager();

	void addEmitter(Emitter &newEmitter);
	void clearEmitter();

	void addParticle(Emitter &e);
	bool updateParticle(Particle *&p, Emitter &e);

	void update(Viewport &viewport);

	float variance();
};

#endif